﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using CoreGallery.Addins.Contracts;

namespace CoreGallery.Core.QueueMgr
{
    /// <summary>
    /// Runs in the background to accept work requests and to dispatch them.
    /// Also periodically serializes items to disk to prevent loss in the
    /// event of instability.
    /// </summary>
    public class ActionQueue
    {
        private List<CoreActionItem> _items = new List<CoreActionItem>();
        private CoreActionStatus _status = CoreActionStatus.NotStarted;

        public void StartDispatcher()
        {
            _status = CoreActionStatus.Running;
        }

        public void StopDispatcher()
        {
            _status = CoreActionStatus.Stopped;
        }

        public CoreActionStatus Status
        {
            get { return _status; }
            set { _status = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="addin">Addin responsible for this action item (to call back for actual processing)</param>
        /// <param name="state">Addin-specific data to reference work item</param>
        /// <returns></returns>
        public CoreActionItem AddToActionQueue(ICoreAddinBase addin, ISerializable state)
        {
            CoreActionItem newItem = new CoreActionItem(addin, state);
            _items.Add(newItem);
            return newItem;
        }

        public void UpdateProgress(CoreActionItem item, int progress)
        {
        }
    }
}
